<?php
/**
 *
 * This file contains {@link Domain51_Service_Delicious_Posts_Container}
 *
 *
 * @package Domain51
 *
 * @subpackage Domain51_Service
 *
 * @author Travis Swicegood <development [at] domain51 [dot] com>
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 *
 */


/**
 *
 * This serves as a container for results from the various methods of
 * {@link Domain51_Service_Delicious_Posts}.
 *
 * This class should generally only be instantiated from within one of the 
 * action methods within {@link Domain51_Service_Delicious_Posts}.
 *
 *
 * @package Domain51
 *
 * @subpackage Domain51_Service
 *
 * @author Travis Swicegood <development [at] domain51 [dot] com>
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 *
 */
class Domain51_Service_Delicious_Posts_Container
{
    private $_meta = array();
    private $_data = array();
    
    
    /**
     *
     * Handle instantiation
     *
     *
     * @param SimpleXMLElement $xml SimpleXML result of a request
     *
     * @param string $type Name of the element that serves as the data
     *
     */
    public function __construct(SimpleXMLElement $xml, $type = 'post') {
        foreach ($xml->attributes() as $key => $value) {
            $this->_meta[$key] = (string)$value;
        }
        
        $i = 0;
        foreach ($xml->$type as $data_key => $data) {
            foreach ($data->attributes() as $key => $value) {
                $this->_data[$i][$key] = (string)$value;
            }
            $i++;
        }
    }
    
    
    /**
     *
     * Returns an array of meta data associated with these results
     *
     *
     * @return array
     *
     */
    public function meta() {
        return $this->_meta;
    }
    
    
    /**
     *
     * Returns an array of actual data associated with these results
     *
     *
     * @return array
     *
     */
    public function data() {
        return $this->_data;
    }
    
}

?>